package set_config


import (
	"fmt"
	"github.com/spf13/viper"  //加载配置文件库
)

//yaml映射结构体
type Config struct {
	Data   DataConfig   `mapstructure:"data"`
	Mysql  MysqlConfig  `mapstructure:"mysql"`
	Python PythonConfig `mapstructure:"python"`
}

//配置结构体
type DataConfig struct {
	RootPath 	  string `mapstructure:"RootPath"`
	Excel_Python  string `mapstructure:"Excel_Python"`
	Pic_Python    string `mapstructure:"Pic_Python"`
	FileName	  string `mapstructure:"FileName"`
	Robot_Webhook string `mapstructure:"Robot_Webhook"`
	File_Webhook  string `mapstructure:"File_Webhook"`	 
}

type MysqlConfig struct {
	Host	 string `mapstructure:"Host"`
  	Port	 int    `mapstructure:"Port"`
  	DBname	 string `mapstructure:"DBname"`
  	Username string `mapstructure:"Username"`
  	Password string `mapstructure:"Password"`
}

type PythonConfig struct {
	RootPath string `mapstructure:"RootPath"`
	FileName string `mapstructure:"FileName"`
	Range	 string `mapstructure:"Range"`	 
}


func Load_Config(path string) *Config { //使用指针类型
	fmt.Println("加载配置文件...")
	viper.SetConfigName("config") //配置文件名称
	viper.SetConfigType("yaml")   //文件类型
	viper.AddConfigPath(path) //配置文件路径

	//读取配置文件
	if err := viper.ReadInConfig(); err != nil {
		fmt.Println("读取配置文件失败:", err)
	}

	var config* Config

	if err := viper.Unmarshal(&config); err != nil {
		fmt.Println("映射配置文件失败:", err)
	}
	
	return config
}
